package com.tgu.home_action.dao;

import com.tgu.home_action.pojo.Banner;
import com.tgu.home_action.pojo.Notice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoticeMapper {
    List<Notice> getNoticesByRoleId(int roleId);

    /**
     * 用户查询公告
     */
    List<Notice> getNotices(Notice notice);

    /**
     * 用户查询Banner
     */
    List<Banner> getBanners(Banner banner);

    /**
     * 查询符合条件的公告数量
     */
    int getNoticesSum(Notice notice);

    /**
     * 分页查询公告
     */
    List<Notice> adminGetNotice(Notice notice);

    /**
     * 插入公告
     */
    @Insert("insert into notices (title,description,content,publisher,publisher_id,display,time,role_id, pageno)" +
            "values (#{title},#{description},#{content},#{publisher},#{publisherId},#{display},#{time},#{roleId},1)")
    void insertNotice(Notice notice);

    /**
     * 修改公告
     */
    Boolean updateNotice(Notice notice);

    /**
     * 删除公告
     */
    @Delete("delete from notices where id=#{id}")
    Boolean delNotice(Integer id);

    /**
     * 通过Id查询公告
     */
    @Select("select * from notices where id=#{id}")
    Notice getNoticeById(Integer id);

    /**
     * 查询符合条件的Banners数量
     */
    int getBannersSum(Notice notice);

    /**
     * 管理员查询Banners
     */
    List<Banner> adminGetBanner(Notice notice);

    /**
     * 插入Banner
     */
    @Insert("insert into banners (url,notice_id,time)" +
            "values (#{url},#{noticeId},#{time})")
    void insertBanner(Banner banner);

    /**
     * 修改Banner
     */
    Boolean updateBanner(Banner banner);

    /**
     * 删除Banner
     */
    @Delete("delete from banners where id=#{id}")
    Boolean delBanner(Integer id);

    /**
     * 通过Id查询banner
     */
    Banner getBannerById(Integer id);

    /**
     * 通过noticeId删除Banner
     */
    @Delete("delete from banners where notice_id=#{noticeId}")
    void delBannerByNoticeId(Integer noticeId);
}
